require_relative "skype/message"
require_relative "skype/room"

module Fabriq
  module Skype
    class << self

      attr_accessor :adapter

      def adapter
        @adapter || Fabriq::Adapter
      end

      def rooms
        adapter.rooms
      end

      def room_by_id(room_id)
        rooms.select { |room| room.id == room_id }.first
      end

      def send_message(message)
        adapter.enqueue_outgoing_message(message)
      end

      def listen_for_messages_to_self(&block)
        adapter.subscribe_to_incoming_messages do |message|
          if message.private_session? || message.direct?
            block.call(message)
          end
        end
      end
      
    end
  end
end